<template>
    <div class="">
        <el-dialog
                :title="title"
                :visible.sync="dialogFormVisible"
                width="600px"
                :close-on-click-modal="false"
                @close="close"
        >
           <div class="t_c">
               <div>
                   <img :src="codeimg" style="width: 200px;height: 200px;">
               </div>
               <a :href='downloadCode(codeimg)' :title="'Id：'+form.id"><el-button size="medium" type="primary" class="mar_t20">下载二维码图片</el-button></a>
           </div>
<!--            <div slot="footer" class="dialog-footer">-->
<!--                <el-button size="medium" @click="close">取 消</el-button>-->
<!--                <el-button size="medium" type="primary" @click="save">确 定</el-button>-->
<!--            </div>-->
        </el-dialog>
    </div>
</template>

<script>
    import {getCode} from "@/api/setup";
    import index from '../../../api/index';

    export default {
        name: "meteriaSave",
        created() {
        },
        data() {
            return {
                form: {
                    id: '',
                    sort: '1',
                    name: "",
                    people: "",
                    areaId: [],
                    typeId: '',
                },
                codeimg:'',
                number:'',
                title: "",
                dialogFormVisible: false,
            }
        },
        components: {},
        methods: {
            showEdit(row) {
                if (!row) {
                    this.title = "新增桌位";
                } else {
                    this.title = "小程序码";
                    this.getCode(row.id)
                    this.form.id = row.id
                    // this.form = Object.assign({}, row);
                }
                this.dialogFormVisible = true;
            },
            setStoreId(storeId){
                this.form.storeId = storeId
            },
            async getCode(id) {
                const {data} = await getCode({tableId:id,page:'yb_wm/shop/in/goods',ident:'table',storeId:this.form.storeId});
                this.codeimg = data?data:''
            },
            downloadCode(row){
                let backendPath = index.backendPath
                return backendPath + "channel/in-store/download-code?url="+row
            },
            close() {
                // this.$refs["form"].resetFields();
                // this.form = this.$options.data().form;
                this.dialogFormVisible = false;
            },
            // save() {
            //     throw variable
            //     this.$refs["form"].validate(async (valid) => {
            //         if (valid) {
            //             const {msg} = await saveTable(this.form);
            //             this.$baseMessage(msg, "success");
            //             this.$emit("fetchData");
            //             this.close();
            //         } else {
            //             return false;
            //         }
            //     });
            // },
        }
    };
</script>
